﻿<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<?php
include("siteName.php");
$disabled = "";
$msg = "";
require("dbInc.php");
include("random.php");
include("sendMail.php");
if (isset($_POST["btnRegister"])) {
if (filter_var($_POST["txtEmail"], FILTER_VALIDATE_EMAIL)) {
$mysqliObj = new mysqli($dbHost, $dbUser, $dbPass, $dbDB);
$eMail = "'" . mysqli_real_escape_string($mysqliObj, $_POST["txtEmail"]) . "'";
$eEmail = $_POST["txtEmail"];
$title = "'" .  mysqli_real_escape_string($mysqliObj, $_POST["selTitle"]) . "'";
$eTitle = $_POST["selTitle"];
$fName = "'" .  mysqli_real_escape_string($mysqliObj, $_POST["txtFName"]) . "'";
$eFName = $_POST["txtFName"];
$lName = "'" .  mysqli_real_escape_string($mysqliObj, $_POST["txtLName"]) . "'";
$eLName = $_POST["txtLName"];
$phone = "'" .  mysqli_real_escape_string($mysqliObj, $_POST["txtPhone"]) . "'";
$ePassword = randomString(6);
$password = "'" . $ePassword . "'";
//check if not an existing e-mail already
$sql = sprintf("select id from %s where vEmail = %s;", $tableUsers, $eMail);
$res = $mysqliObj->query($sql);
$res->data_seek(0);
if ($res->num_rows < 1) {
$sql = "insert into %s (vEmail, vPassword, vTitle, vFirstName, vLastName, vPhone) values (%s, %s, %s, %s, %s, %s);";
$sql = sprintf($sql, $tableUsers, $eMail, $password, $title, $fName, $lName, $phone);
$mysqliObj->query($sql);
$subject = $siteName . " registration";
$body = "<h3>" . $siteName . " registration</h3>\n<p>Hullo there, " . $eTitle . " " . $eFName . " " . $eLName . ".<br /><br />\nYou have registered this e-mail address (" . $eEMail . "), on the " . $siteName . " website:-<br />\n";
$body .= "<a href='" . $siteAddress . "' target='_blank'>" . $siteAddress . "</a><br /><br />\n";
$body .= "You can login there using this e-mail address:<br />\n" . $eEMail . "<br /><br />\n and the following password, which can then be changed once you've logged in for first time:<br />\n" . $ePassword . "<br />\n";
sendMail($to, $body, $subject);
$msg = "Your e-mail address has now been registered, and an initial password has been e-mailed to you, and you will be able to change it once you have logged in for first time";
$disabled = " disabled";
} else {
$msg = "That e-mail address is already registered - maybe try make use of lost password page if you can't remember password?";
}//end of checking if already registered with email
$mysqliObj->close();
} else {
$msg = "You must enter a valid e-mail address";
}//end of checking if valid email address
}//end of checking form submission
?>
<title><?php echo $siteName; ?> Registration</title>
<link type="text/css" rel="stylesheet" href="styles.css" />
<?php
include("includefunctions.inc");
?>
<script type="text/javascript" language="javascript">
function validateForm(theForm) {
with (theForm) {
if (validate_required(txtEmail,"You must enter an e-mail address")==false)
{txtEmail.focus();return false}
if (validate_email(txtEmail,"You must enter a valid e-mail address")==false)
{txtEmail.focus();return false}
if (validate_required(txtFName,"You must enter a first name")==false)
{txtFName.focus();return false}
if (validate_required(txtLName,"You must enter a last name")==false)
{txtLName.focus();return false}
}//end of with clause
}//end of validateForm function

function checkMsg() {
var msg = "<?php echo $msg; ?>";
if (msg.length > 0) {
alert(msg);
}
}//end of checkMsg function
</script>
</head>
<body onload="checkMsg();">
<iframe name="logoFrame" id="logoFrame" src="logo.htm" border="0" height="120" align="top" frameborder="0" marginheight="0" width="100%" scrolling="no">
<a href="http://www.blindza.co.za/" target="_blank">
<img src="logo/blindza_logo_smaller46.jpg" alt="blindZA.co.za logo - white text on black background, with white border - and red braille version hovering in front of normal text" width="317" height="103" border="0" />
</a>
</iframe>
<a href="index.php">Back to entry page</a>
<h2><?php echo $siteName; ?> registration</h2>
<p>In order to make use of the shopping facilities on this site, you should fill out the relevant information below - all fields marked with a * are required</p>
<?php
if (strlen($msg) > 0) {
echo "<p class='error'>" . $msg . "</p>\n";
}
?>
<form action="register.php" method="post" enctype="multipart/form-data" onsubmit="return validateForm(this);">
<table align="center" border="0">
<tr>
<th align="right">e-Mail address *:</th>
<td>
<input type="text" id="txtEmail" name="txtEmail" />
</td>
</tr>
<tr>
<th align="right">Title:</th>
<td>
<select name="selTitle">
<option value="" selected></option>
<option value="Mr.">Mr.</option>
<option value="Mrs.">Mrs.</option>
<option value="Ms.">Ms.</option>
<option value="Prof.">Prof.</option>
<option value="Dr.">Dr.</option>
</select>
</td>
</tr>
<tr>
<th align="right">First name *:</th>
<td>
<input type="text" id="txtFName" name="txtFName" />
</td>
</tr>
<tr>
<th align="right">Last name *:</th>
<td>
<input type="text" id="txtLName" name="txtLName" />
</td>
</tr>
<tr>
<th align="right">Phone number:</th>
<td>
<input type="text" id="txtPhone" name="txtPhone" />
</td>
</tr>
<tr>
<th align="center" colspan="2">
<input type="submit" name="btnRegister" value="Register" <?php echo $disabled; ?>/><br />
<input type="reset" name="btnReset" value="Reset" />
</th>
</tr>
</table>
</form>
</body>
</html>
